package thread09.thread.productorconsumer.test1;

class Info
{
	private String name = "刘兆清";
	private String content = "java菜鸟";

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public String getContent()
	{
		return content;
	}

	public void setContent(String content)
	{
		this.content = content;
	}
}

class Producer implements Runnable
{
	private Info info = null;

	public Producer(Info info)
	{
		this.info = info;
	}

	public void run()
	{
		// TODO Auto-generated method stub
		boolean flag = false;
		for(int i = 0; i < 50; i++)
		{
			if(flag)
			{
				this.info.setName("刘兆清");
				try
				{
					Thread.sleep(120);
				}
				catch(InterruptedException e)
				{
					e.printStackTrace();
				}
				this.info.setContent("java菜鸟");
				flag = false;
			}
			else
			{
				this.info.setName("刘溯海");
				try
				{
					Thread.sleep(120);
				}
				catch(InterruptedException e)
				{
					e.printStackTrace();
				}
				this.info.setContent("java大师");
				flag = true;
			}
			
		}
	}
}

class Consumer implements Runnable
{
	private Info info = null;

	public Consumer(Info info)
	{
		this.info = info;
	}

	public void run()
	{
		// TODO Auto-generated method stub
		//boolean flag = false;
		for(int i = 0; i < 50; i++)
		{
			
				try
				{
					Thread.sleep(120);
				}
				catch(InterruptedException e)
				{
					e.printStackTrace();
				}
				
			System.out.println(this.info.getName()+"---->"+this.info.getContent());
		}
	}
}

public class TestInfo
{
	public static void main(String args[])
	{
		Info info = new Info();
		Producer pro = new Producer(info);
		Consumer con = new Consumer(info);
		new Thread(pro).start();
		new Thread(con).start();
	}
}